<div class="modal fade " id="addPermissionModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">新增用户角色</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal" id="addPermissionForm">
                <div class="box-body">
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">父菜单</label>
                        <div class="col-sm-7">
                            <select id="addPermission_parentId" class=" form-control select2" style="width: 100%">
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">菜单名称</label>
                        <div class="col-sm-7">
                            <input id="addPermission_name" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">图标</label>
                        <div class="col-sm-7">
                            <input id="addPermission_icon" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">链接</label>
                        <div class="col-sm-7">
                            <input id="addPermission_url" type="text" class="form-control">
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>

                    <button type="button" class="btn btn-primary pull-right" onclick="addPermissionModal_save()">保存</button>
                </div>
                <!-- /.box-footer -->
            </form>
        </div>
    </div>
</div>
<script>
    function addPermissionModal_init() {
        $("#addPermission_parentId").empty();
        $("#addPermission_name").val("");
        $("#addPermission_icon").val("");
        $("#addPermission_url").val("");
        var url = "/permission/parent/list";
        setFormValue(url,"addPermission_parentId","#") ;
    }

    function addPermissionModal_save() {
        var name = $("#addPermission_name").val();
        if (name == null || name == undefined || name == "" || name.trim() == "") {
            toastr['error']("菜单名称不能为空", '异常');
            return;
        }
        var url = $("#addPermission_url").val();
        if (url == null || url == undefined || url == "" || url.trim() == "") {
            toastr['error']("链接不能为空", '异常');
            return;
        }
        var data = {
            parentId: $("#addPermission_parentId").val(),
            name: name,
            url:url,
            icon:$("#addPermission_icon").val()
        };
        var url = "/permission/add";
        postReq(url, data, function (result) {
            if (result.success) {
                $("#permissionTable").bootstrapTable("refresh");
                $("#addPermissionModal").modal("hide");
                toastr['success']('新增菜单成功', '提示');
            } else {
                toastr['error'](result.msg, '提示');
            }
        });
    }


</script>